﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Admin_Country_NewCountry : AdminBasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (isLogin())
        {
            if (LoginedStaff.tblRole.Role != "Admin")
                Response.Redirect("~/Admin/Index.aspx");
        }
        else
        {
            Response.Redirect("~/Admin/Stafflogin.aspx");
        }
    }
    protected void CreateButton1_Click(object sender, EventArgs e)

    {
        countryLabel.Visible = false;
        priceRateLabel.Visible = false;

        decimal dd;

        bool feeCheck = Decimal.TryParse(PriceRate.Text, out dd);
        if (string.IsNullOrEmpty(PriceRate.Text) || Convert.ToDecimal(PriceRate.Text) <= 0)
        {
            feeCheck = false;
        }
        if (!string.IsNullOrEmpty(CountryName.Text) && feeCheck)
        {
            MailDistributionSystemDBDataContext db = new MailDistributionSystemDBDataContext();
            if (db.tblCountries.Where(c => c.Country == CountryName.Text.Trim()).Count() == 0)
            {
                tblCountry country = new tblCountry();
                country.Country = CountryName.Text.Trim();
                country.PriceRate = Convert.ToDecimal(PriceRate.Text);
                db.tblCountries.InsertOnSubmit(country);
                db.SubmitChanges();
                Response.Redirect("~/Admin/Country/ViewCountry.aspx");
            }
            else
            {
                ScriptManager.RegisterStartupScript(this, this.GetType(), "alert", "alert('Country Already Exist!')", true);
            }
        }
        else
        {
            if (string.IsNullOrEmpty(CountryName.Text))
            {
                countryLabel.Visible = true;
            }
            if (!feeCheck)
            {
                priceRateLabel.Visible = true;
            }
        }
        
    }
    protected void TextBox1_TextChanged(object sender, EventArgs e)
    {

    }
}